﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Remider.Entity;

namespace Remider.Forms
{
    public partial class TipForm : Form
    {
        private Appointment _current;
        internal Appointment Current
        {
            get
            {
                return _current;
            }
            set
            {
                _current = value;
                Text = _current.Title;
                ContentTextBox.Text = _current.Content;
            }
        }

        public TipForm()
        {
            InitializeComponent();
        }

        private void OkButton_Click(object sender, EventArgs e)
        {
            _current.LaterRunDate = null;
            _current.SetNextRunDate();
            Close();
        }

        private void LaterButton_Click(object sender, EventArgs e)
        {
            if (_current.LaterRunDate == null)
            {
                _current.LaterRunDate = _current.NextRunDate.AddMinutes(int.Parse(laterTextBox.Text.Trim()));
            }
            else
            {
                _current.LaterRunDate = _current.LaterRunDate.Value.AddMinutes(int.Parse(laterTextBox.Text.Trim()));
            }
            Close();
        }

        private void TipForm_MouseDown(object sender, MouseEventArgs e)
        {
            int xOffset;
            int yOffset;
            if (e.Button == MouseButtons.Left)
            {
                var mos = PointToScreen(e.Location);
                xOffset = mos.X - Location.X;
                yOffset = mos.Y - Location.Y;
                MouseOffset = new Point(-xOffset, -yOffset);
                IsMouseDown = true;
            }

        }

        protected Point MouseOffset { get; set; }

        protected bool IsMouseDown { get; set; }

        private void TipForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (IsMouseDown)
            {
                Point mousePos = Control.MousePosition;
                mousePos.Offset(MouseOffset.X, MouseOffset.Y);
                Location = mousePos;
            }
        }

        private void TipForm_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                IsMouseDown = false;
            }
        }

        private void TipForm_Load(object sender, EventArgs e)
        {
            //var formPath = new GraphicsPath();
            //formPath.AddLine(5, 230, 5, 200);
            //formPath.AddLine(5, 200, 95, 200);
            //formPath.AddLine(95, 200, 95, 30);
            //formPath.AddLine(95, 30, 250, 30);
            //formPath.AddLine(250, 30, 250, 200);
            //formPath.AddLine(250, 200, 340, 200);
            //formPath.AddLine(340, 200, 340, 230);
            //formPath.AddLine(340, 230, 5, 230);
            //formPath.CloseFigure();
            //this.Region = new Region(formPath);
        }
    }
}
